<?php
    header('Context-Type:Text/html;charset:utf-8');
	require 'liuyanban.class.php';
	
	
	//显示评论的数量
	function countmessage(){
	$db=new sql_server();
	//	$db->__construct();
	$db->set_character();
	$sql='SELECT COUNT(*) FROM liuyan';
	$count=$db->execute_dql($sql);
	$countnum=$count->fetch_assoc();
	return $countnum["COUNT(*)"];
	
	$db->close_connect();
	}
	
	//发布评论
	if(isset($_POST['textline'])){
		echo $_POST['textline'];
		$db=new sql_server();
		$db->set_character();
		$sql="INSERT INTO liuyan (id,username,date,message)
		VALUES ('6', 'XXF', '2021-5-6','i give you all my monkey')";
    	$db->execute_dql($sql);
	
		$db->close_connect();
	}
	
	//显示数据库内的数据
	$db=new sql_server();
	$db->set_character();
	$sql="SELECT username,date,message FROM liuyan";
	$count=$db->execute_dql($sql);
//	$countnum=$count->fetch_assoc();
//	
	
	
	//生成分页样子
	//获取数据库内数据的数量
		$total_num = countmessage();
		//每页显示的数量
		$perpage=4;
		//获取当前页
		$page=isset($_GET['page'])?(int)$_GET['page']:1;
		//获取总页数
		$total_page = ceil($total_num/$perpage);
		$page = max($page,1);
		$page = min($page,$total_page);
		
	
	
	//遍历生成每页的坐标
   	$start_index = $perpage*($page-1);

	$end_index = $perpage*$page-1;

	$end_index = min($end_index,$total_num-1);
	
	
	
	
	//查询数据库数据的数量并显示
	require '实训项目.html';
	//关闭数据库链接
	$db->close_connect();
	